//
//  MBProgressHUD+MoreExtensions.m
//  KGPlayer
//
//  Created by neuedu on 15/10/20.
//  Copyright (c) 2015 年 neuedu. All rights reserved.
//

#import "MBProgressHUD+MoreExtensions.h"
#import<objc/runtime.h>
#import "bleHeader.h"

static char extensionKey;

@implementation MBProgressHUD (MoreExtensions)
@dynamic delegateExtension;

- (void) setDelegateExtension:(id<MBProgressHUDExtensionsDelegate>)delegateExtension
{
    objc_setAssociatedObject (self, &extensionKey, delegateExtension, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (id<MBProgressHUDExtensionsDelegate>)delegateExtension
{
    return objc_getAssociatedObject(self, &extensionKey);
}

+(instancetype)showHUDAddedTo:(UIView *)view WithLabel:(NSString *)label animated:(BOOL)animated{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    hud.bezelView.color = [UIColor blackColor];
    hud.bezelView.alpha = 0.8f;
    hud.contentColor = [UIColor whiteColor];//将转圈和文字设置成白色
    
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.detailsLabel.text = label;
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.animationType = MBProgressHUDAnimationZoomOut;
    return hud;
}

+(instancetype)showHUDAddedTo:(UIView *)view WithLabel:(NSString *)label offset:(CGFloat)yOffset delay:(NSTimeInterval)delay font:(UIFont*)font animated:(BOOL)animated{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
  
    hud.bezelView.color = [UIColor blackColor];
    hud.bezelView.alpha = 0.8f;
    hud.contentColor = [UIColor whiteColor];//将转圈和文字设置成白色
    
    hud.detailsLabel.text = label;
    hud.detailsLabel.font = font;
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.animationType = MBProgressHUDAnimationZoomOut;
    [hud setOffset: CGPointMake(0.f, yOffset)];
    [hud hideAnimated:YES afterDelay:delay];
    return hud;
}

+(instancetype)showTipHUDAddedTo:(UIView *)view WithLabel:(NSString *)tip {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = tip;
    CGFloat y = [UIScreen mainScreen].bounds.size.height*0.25;
    [hud setOffset: CGPointMake(0.f, y)];
    [hud hideAnimated:YES afterDelay:2.5f];
    return hud;
}

+(instancetype)showTipHUDAddedTo:(UIView *)view WithLabel:(NSString *)tip offset:(CGFloat)yOffset delay:(NSTimeInterval)delay {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = tip;
    [hud setOffset: CGPointMake(0.f, yOffset)];
    [hud hideAnimated:YES afterDelay:delay];
    return hud;
}

+(instancetype)showTipHUDAddedTo:(UIView *)view WithLabel:(NSString *)tip offset:(CGFloat)yOffset delay:(NSTimeInterval)delay font:(UIFont*) font multiLine: (bool) bMultiLine contentColor:(UIColor*) ctColor bgColor:(UIColor*) bgColor alpha:(CGFloat) alpha {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.color = bgColor;
    hud.bezelView.alpha = alpha;
    hud.contentColor = ctColor;
    
    if (bMultiLine) {
        hud.detailsLabel.font = font;
        hud.detailsLabel.text = tip;
    } else {
        hud.label.font = font;
        hud.label.text = tip;
    }

    [hud setOffset: CGPointMake(0.f, yOffset)];
    [hud hideAnimated:YES afterDelay:delay];
    return hud;
}

+(instancetype)showTipHUDAddedTo:(UIView *)view tip:(NSString *)tip afterDelay:(NSTimeInterval)delay {
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = tip;
    CGFloat y = [UIScreen mainScreen].bounds.size.height*0.25;
    [hud setOffset: CGPointMake(0.f, y)];
    [hud hideAnimated:YES afterDelay:delay];
    return hud;
}

+(instancetype)showBigRectangleView:(NSString *)tip{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.frame = CGRectMake(37.5f/375.f*SCREEN_WIDTH, 200.f/667.f*SCREEN_HEIGHT, 300.f/375.f*SCREEN_WIDTH, 190.f/667.f*SCREEN_HEIGHT);
    hud.label.text = tip;
    [hud hideAnimated:YES afterDelay:1.f];
    return hud;
}

+(instancetype)showBigRectangleAddedTo:(UIView *)view tip:(NSString *)tip{
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.frame = CGRectMake(37.5f/375.f*SCREEN_WIDTH, 200.f/667.f*SCREEN_HEIGHT, 300.f/375.f*SCREEN_WIDTH, 190.f/667.f*SCREEN_HEIGHT);
    hud.label.text = tip;
    [hud hideAnimated:YES afterDelay:2.f];
    return hud;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (nil != self.delegateExtension) {
        if ([self.delegateExtension respondsToSelector:@selector(hudViewWasTapped)]) {
            [self.delegateExtension performSelector:@selector(hudViewWasTapped)];
        }
    }
}

@end
